# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

from utils.models import BaseModel
from users.models import CompanyInfo, Person
from basic.models import ElevatorInfo

# Create your models here.


class RescueTask(BaseModel):
    rescue_no = models.CharField(max_length=50, unique=True, verbose_name=u"救援任务单号")
    elevator = models.ForeignKey(ElevatorInfo, verbose_name=u"电梯", related_name="rescue_elevator",
                                 null=True, blank=True)
    elevator_code = models.CharField(max_length=20, verbose_name=u"电梯注册码", null=True, blank=True)
    g_uid = models.CharField(max_length=50, verbose_name=u"聆讯平台唯一序号", null=True, blank=True)
    task_creator_id = models.CharField(max_length=50, verbose_name=u"坐席人员ID", null=True, blank=True)
    task_creator_name = models.CharField(max_length=20, verbose_name=u"坐席人员姓名", null=True, blank=True)
    task_creator_phone = models.CharField(max_length=11, verbose_name=u"坐席人员电话", null=True, blank=True)
    task_create_time = models.DateTimeField(verbose_name=u"任务单创建时间", null=True, blank=True)
    task_depict = models.TextField(verbose_name=u"任务描述", null=True, blank=True)
    rescue_depict = models.TextField(verbose_name=u"救援描述", null=True, blank=True)
    TASK_STATUS_0 = 0
    TASK_STATUS_1 = 10
    TASK_STATUS_2 = 20
    TASK_STATUS_3 = 30
    TASK_STATUS_4 = 40
    TASK_STATUS_5 = 50
    TASK_STATUS_6 = 60
    TASK_STATUS_7 = 70
    TASK_STATUS_8 = 80
    TASK_STATUS_9 = 90
    TASK_STATUS_10 = 100
    TASK_STATUS = (
        (TASK_STATUS_0, u"任务已创建"),
        (TASK_STATUS_1, u"任务已接收"),
        (TASK_STATUS_2, u"任务已接受"),
        (TASK_STATUS_3, u"任务已开始"),
        (TASK_STATUS_4, u"任务已拒绝"),
        (TASK_STATUS_5, u"任务拒绝审核中"),
        (TASK_STATUS_6, u"任务拒绝提交失败"),
        (TASK_STATUS_7, u"任务拒绝未通过"),
        (TASK_STATUS_8, u"任务误报待核实"),
        (TASK_STATUS_9, u"任务误报已确认"),
        (TASK_STATUS_10, u"任务已完成"),
    )
    rescue_state = models.IntegerField(choices=TASK_STATUS, verbose_name=u"救援任务状态", default=TASK_STATUS_0)
    coordinate_system = models.IntegerField(verbose_name=u"坐标系", default=2)
    maintain_company = models.ForeignKey(CompanyInfo, verbose_name=u"维保单位", related_name="rescue_company",
                                         null=True, blank=True)
    rescuer = models.ForeignKey(Person, verbose_name=u"救援人员", related_name="rescue_person", null=True, blank=True)
    rescuer_name = models.CharField(max_length=20, verbose_name=u"救援人员姓名", null=True, blank=True)
    rescuer_phone = models.CharField(max_length=11, verbose_name=u"救援人员手机", null=True, blank=True)
    rescuer_coordinates = models.CharField(max_length=128, verbose_name=u"救援人员坐标", null=True, blank=True)
    rescuer_state = models.IntegerField(verbose_name=u"救援人员状态", default=0)
    property_company = models.ForeignKey(CompanyInfo, verbose_name=u"使用单位", related_name="rescue_property_company",
                                         null=True, blank=True)
    property_company_name = models.CharField(max_length=20, verbose_name=u"使用单位名称", null=True, blank=True)
    property_company_phone = models.CharField(max_length=128, verbose_name=u"使用单位电话", null=True, blank=True)
    terminal_name = models.CharField(max_length=20, verbose_name=u"救援终端名", null=True, blank=True)
    warn_bill_no = models.CharField(max_length=50, verbose_name=u"报警单号", null=True, blank=True)
    warn_bill_coordinates = models.CharField(max_length=128, verbose_name=u"报警坐标", null=True, blank=True)
    warn_bill_time = models.DateTimeField(verbose_name=u"报警时间", null=True, blank=True)
    remark = models.TextField(verbose_name=u"备注", null=True, blank=True)
    lng = models.CharField(max_length=50, verbose_name=u"经度", null=True, blank=True)
    lat = models.CharField(max_length=50, verbose_name=u"纬度", null=True, blank=True)
    confirm_media = models.TextField(verbose_name=u"拒绝任务的材料", null=True, blank=True)
    refuse_reason = models.TextField(verbose_name=u"拒绝任务的原因", null=True, blank=True)
    rescuer_receive_time = models.DateTimeField(verbose_name=u"接受任务时间", null=True, blank=True)
    rescuer_confirm_time = models.DateTimeField(verbose_name=u"确认任务时间", null=True, blank=True)
    rescuer_refuse_time = models.DateTimeField(verbose_name=u"拒绝任务时间", null=True, blank=True)
    rescuer_arrive_time = models.DateTimeField(verbose_name=u"到达现场的时间", null=True, blank=True)
    reject_reason = models.TextField(verbose_name=u"拒绝任务未通过原因", null=True, blank=True)



